package com.ruoyi.web.controller.control;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.control.domain.ApiEndpoints;
import com.ruoyi.control.service.IApiEndpointsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * API接口信息Controller
 * 
 * @author hcc
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/control/endpoints")
public class ApiEndpointsController extends BaseController
{
    @Autowired
    private IApiEndpointsService apiEndpointsService;

    /**
     * 查询API接口信息列表
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiEndpoints apiEndpoints)
    {
        startPage();
        List<ApiEndpoints> list = apiEndpointsService.selectApiEndpointsList(apiEndpoints);
        return getDataTable(list);
    }

    /**
     * 导出API接口信息列表
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:export')")
    @Log(title = "API接口信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiEndpoints apiEndpoints)
    {
        List<ApiEndpoints> list = apiEndpointsService.selectApiEndpointsList(apiEndpoints);
        ExcelUtil<ApiEndpoints> util = new ExcelUtil<ApiEndpoints>(ApiEndpoints.class);
        util.exportExcel(response, list, "API接口信息数据");
    }

    /**
     * 获取API接口信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:query')")
    @GetMapping(value = "/{apiId}")
    public AjaxResult getInfo(@PathVariable("apiId") String apiId)
    {
        return success(apiEndpointsService.selectApiEndpointsByApiId(apiId));
    }

    /**
     * 新增API接口信息
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:add')")
    @Log(title = "API接口信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiEndpoints apiEndpoints)
    {
        return toAjax(apiEndpointsService.insertApiEndpoints(apiEndpoints));
    }

    /**
     * 修改API接口信息
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:edit')")
    @Log(title = "API接口信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiEndpoints apiEndpoints)
    {
        return toAjax(apiEndpointsService.updateApiEndpoints(apiEndpoints));
    }

    /**
     * 删除API接口信息
     */
    @PreAuthorize("@ss.hasPermi('control:endpoints:remove')")
    @Log(title = "API接口信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{apiIds}")
    public AjaxResult remove(@PathVariable String[] apiIds)
    {
        return toAjax(apiEndpointsService.deleteApiEndpointsByApiIds(apiIds));
    }
}
